﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;

namespace InnovTech.Util.Resources.Test
{
    [TestClass]
    [DeploymentItem("TestStuffs")]
    public class TestResxFileCollection
    {
        static string AppFrameNeutralResx = "AppFrameUIResources.resx";
        static string AppFrameUSResx = "AppFrameUIResources.en-US.resx";
        static string AppFrameDEResx = "AppFrameUIResources.de-DE.resx";

        static string ControlCenterNeutralResx = "AppFrameControlCenterUIResources.resx";
        static string ControlCenterUSResx = "AppFrameControlCenterUIResources.en-US.resx";
        static string ControlCenterDEResx = "AppFrameControlCenterUIResources.de-DE.resx";


        [TestMethod]
        public void TestFromDirectory()
        {
            string dir = Directory.GetCurrentDirectory();
            ResxFileCollection collection = ResxFileCollection.FromDirectory(dir);
            Assert.AreEqual(6, collection.Values.Count);
        }

        [TestMethod]
        public void TestGetNeutralFiles()
        {
            string dir = Directory.GetCurrentDirectory();
            ResxFileCollection collection = ResxFileCollection.FromDirectory(dir);

            IEnumerable<ResxFile> neutralResxFiles = collection.GetNeutralFiles();
            Assert.AreEqual(2, neutralResxFiles.Count());

            foreach (var neutral in neutralResxFiles)
            {
                bool correct = Path.GetFileName(neutral.FilePath).Equals(AppFrameNeutralResx);
                correct = correct || Path.GetFileName(neutral.FilePath).Equals(ControlCenterNeutralResx);
                Assert.IsTrue(correct);
            }

        }
        [TestMethod]
        public void TestGetNonNeutralFiles()
        {
            string dir = Directory.GetCurrentDirectory();
            ResxFileCollection collection = ResxFileCollection.FromDirectory(dir);

            IEnumerable<ResxFile> neutralResxFiles = collection.GetNeutralFiles();
            
            

            foreach (var neutral in neutralResxFiles)
            {
                IEnumerable<ResxFile> nonNeutralResxFiles = collection.GetNonNeutralFiles(neutral.FilePath);
                Assert.AreEqual(2, nonNeutralResxFiles.Count());
                nonNeutralResxFiles.ToList().ForEach(file => file.RelatedNeutralFileName.Equals(Path.GetFileNameWithoutExtension(neutral.FilePath)));
            }
        }

        [TestMethod]
        public void TestGetNeutralFile()
        {
            ResxFileCollection collection = new ResxFileCollection();
            ResxFile neutralFile = new ResxFile("", AppFrameNeutralResx);
            ResxFile nonNeutralFile = new ResxFile("", AppFrameUSResx);
            collection.Add(neutralFile);
            collection.Add(nonNeutralFile);

            Assert.AreEqual(neutralFile, collection.GetNeutralFile(neutralFile));
            Assert.AreEqual(neutralFile, collection.GetNeutralFile(nonNeutralFile));
        }
        [TestMethod]
        public void TestAddAndContains()
        {
            ResxFileCollection collection = new ResxFileCollection();
            ResxFile neutralFile = new ResxFile("", AppFrameNeutralResx);
            ResxFile nonNeutralFile = new ResxFile("", AppFrameUSResx);
            collection.Add(neutralFile);
            collection.Add(nonNeutralFile);
            ResxFile third = new ResxFile("", AppFrameDEResx);
            collection.Add(third.FilePath, third);

            ResxFile forth = new ResxFile("", ControlCenterNeutralResx);
            ResxFile fifth = new ResxFile("", ControlCenterUSResx);
            ResxFile sixth = new ResxFile("", ControlCenterDEResx);

            collection.Add(new List<ResxFile>() { forth, fifth, sixth });

            Assert.AreEqual(6, collection.Count);

            Assert.IsTrue(collection.Contains(neutralFile));
            Assert.IsTrue(collection.Contains(neutralFile.FilePath));
            Assert.IsTrue(collection.Contains(nonNeutralFile));
            Assert.IsTrue(collection.Contains(nonNeutralFile.FilePath));
        }
    }
}
